﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;

public partial class GioiThieu_Controls_ControlGioiThieuGroupContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiHoatDong();
            HienThiThanhTich();
            HienThiLichSu();
            HienThiTuyenDung();
            
            // Gioi thieu
            linkHd.NavigateUrl = getLinkGioiThieu(Common.HoatDong);
            linkQtt.NavigateUrl = getLinkGioiThieu(Common.ThanhTich);
            linkLs.NavigateUrl = getLinkGioiThieu(Common.LichSu);
            linkTd.NavigateUrl = getLinkGioiThieu(Common.TuyenDung);
        }
    }

    private void HienThiThanhTich()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubChuyenMuc> TList_SubChuyenMuc = DataRepository.SubChuyenMucProvider.GetPaged("TenSubChuyenMuc like N'%" + Common.ThanhTich + "%'", "Id", 0, 1, out TotalRows);
        if (TList_SubChuyenMuc.Count > 0)
        {
            WhereClause += "and TrangThai = 1 and IdSubChuyenMuc = " + TList_SubChuyenMuc[0].Id;
        }
        else
        {
            WhereClause += "and TrangThai = 1";    
        }
                
        TList<ChuyenMuc> TList_ChuyenMuc_ThanhTich = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 1, out TotalRows);

        if (TList_ChuyenMuc_ThanhTich.Count > 0)
        {
            strHTML += "<div style=\"width: 300px;min-height:315px;height: auto;\">";
            strHTML += "<img class=\"radius\" src=\"Upload/ChuyenMuc/" + TList_ChuyenMuc_ThanhTich[0].AnhDaiDien + "\" width=\"300px\" height=\"150px\" border=\"0\"/>";
            strHTML += "<div style=\"width: 300px;min-height: 70px;height: auto;margin-bottom:10px;word-wrap:break-word;font-family: Arial, Helvetica, sans-serif;font-size: 13px;color:#696969;padding-top:10px;text-align:justify;\">" +
                (TList_ChuyenMuc_ThanhTich[0].TomTat.ToString().Length > 150 ? TList_ChuyenMuc_ThanhTich[0].TomTat.Substring(0, 150) + "..." : TList_ChuyenMuc_ThanhTich[0].TomTat.ToString()) + "</div>";
            strHTML += "<div style=\"width:71px; height: 17px; background:url('Images/dltn/seeMoreBg.png') no-repeat;float:right;\">";
            strHTML += "<a href=\"ChuyenMuc/" + TList_ChuyenMuc_ThanhTich[0].Id + "/" + TList_ChuyenMuc_ThanhTich[0].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc_ThanhTich[0].TieuDe) + ".aspx\" style=\"text-decoration:none; font-size:12px; padding-left:10px;padding-top:2px;color:#fff;\">Xem tiếp</a></div>";
            strHTML += "</div>";

            string ngay = Common.StandardStringjquery(TList_ChuyenMuc_ThanhTich[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));
            
            //if ("Ch".Equals(ngay.Substring(0, 2)))
                lblNgayCapNhatThanhTich.Text = ngay;
            //else
            //    lblNgayCapNhatThanhTich.Text = "Thứ " + ngay;
        }
        else
        {
            strHTML = "<div style=\"width: 300px;min-height:100px;height: auto; clear: both;\">";
            strHTML += "Dữ liệu chưa được cập nhật</div>";
        }

        ltrThanhTich.Text = strHTML;
    }

    private void HienThiHoatDong()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubChuyenMuc> TList_SubChuyenMuc = DataRepository.SubChuyenMucProvider.GetPaged("TenSubChuyenMuc like N'%" + Common.HoatDong + "%'", "Id", 0, 1, out TotalRows);
        WhereClause += "and TrangThai = 1 and IdSubChuyenMuc = " + TList_SubChuyenMuc[0].Id;

        TList<ChuyenMuc> TList_ChuyenMuc_HoatDong = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 1, out TotalRows);

        if (TList_ChuyenMuc_HoatDong.Count > 0)
        {
            strHTML += "<div style=\"width: 300px;min-height:315px;height: auto;\">";
            strHTML += "<img  class=\"radius\" src=\"Upload/ChuyenMuc/" + TList_ChuyenMuc_HoatDong[0].AnhDaiDien + "\" width=\"300px\" height=\"150px\" border=\"0\"/>";
            strHTML += "<div style=\"width: 300px;min-height: 70px;height: auto;margin-bottom:10px;word-wrap:break-word;font-family: Arial, Helvetica, sans-serif;font-size: 13px;color:#696969;padding-top:10px;text-align:justify;\">" +
                (TList_ChuyenMuc_HoatDong[0].TomTat.ToString().Length > 150 ? TList_ChuyenMuc_HoatDong[0].TomTat.Substring(0, 150) + "..." : TList_ChuyenMuc_HoatDong[0].TomTat.ToString()) + "</div>";
            strHTML += "<div style=\"width:71px; height: 17px; background:url('Images/dltn/seeMoreBg.png') no-repeat;float:right;\">";
            strHTML += "<a href=\"ChuyenMuc/" + TList_ChuyenMuc_HoatDong[0].Id + "/" + TList_ChuyenMuc_HoatDong[0].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc_HoatDong[0].TieuDe) + ".aspx\" style=\"text-decoration:none; font-size:12px; padding-left:10px;padding-top:2px;color:#fff;\">Xem tiếp</a></div>";
            strHTML += "</div>";

            string ngay = Common.StandardStringjquery(TList_ChuyenMuc_HoatDong[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));
             
            //if ("Ch".Equals(ngay.Substring(0, 2)))
                lblNgayCapNhatHoatDong.Text = ngay;
            //else
            //    lblNgayCapNhatHoatDong.Text = "Thứ " + ngay;

            
        }
        else
        {
            strHTML = "<div style=\"width: 300px;min-height:100px;height: auto; clear: both;\">";
            strHTML += "Dữ liệu chưa được cập nhật</div>";
        }

        ltrHoatDong.Text = strHTML;
    }

    private void HienThiLichSu()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubChuyenMuc> TList_SubChuyenMuc = DataRepository.SubChuyenMucProvider.GetPaged("TenSubChuyenMuc like N'%" + Common.LichSu + "%'", "Id", 0, 1, out TotalRows);
        WhereClause += "and TrangThai = 1 and IdSubChuyenMuc = " + TList_SubChuyenMuc[0].Id;

        TList<ChuyenMuc> TList_ChuyenMuc_LichSu = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 1, out TotalRows);

        if (TList_ChuyenMuc_LichSu.Count > 0)
        {
            strHTML += "<div style=\"width: 300px;min-height:315px;height: auto;\">";
            strHTML += "<img class=\"radius\" src=\"Upload/ChuyenMuc/" + TList_ChuyenMuc_LichSu[0].AnhDaiDien + "\" width=\"300px\" height=\"150px\" border=\"0\"/>";
            strHTML += "<div style=\"width: 300px;min-height: 70px;height: auto;margin-bottom:10px;word-wrap:break-word;font-family: Arial, Helvetica, sans-serif;font-size: 13px;color:#696969;padding-top:10px;text-align:justify;\">" +
                (TList_ChuyenMuc_LichSu[0].TomTat.ToString().Length > 150 ? TList_ChuyenMuc_LichSu[0].TomTat.Substring(0, 150) + "..." : TList_ChuyenMuc_LichSu[0].TomTat.ToString()) + "</div>";
            strHTML += "<div style=\"width:71px; height: 17px; background:url('Images/dltn/seeMoreBg.png') no-repeat;float:right;\">";
            strHTML += "<a href=\"ChuyenMuc/" + TList_ChuyenMuc_LichSu[0].Id + "/" + TList_ChuyenMuc_LichSu[0].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc_LichSu[0].TieuDe) + ".aspx\" style=\"text-decoration:none; font-size:12px; padding-left:10px;padding-top:2px;color:#fff;\">Xem tiếp</a></div>";
            strHTML += "</div>";

            string ngay = Common.StandardStringjquery(TList_ChuyenMuc_LichSu[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));

            //if ("Ch".Equals(ngay.Substring(0, 2)))
                lblNgayCapNhatLichSu.Text = ngay;
            //else
            //    lblNgayCapNhatLichSu.Text = "Thứ " + ngay;
             
        }
        else
        {
            strHTML = "<div style=\"width: 300px;min-height:100px;height: auto;\">";
            strHTML += "Dữ liệu chưa được cập nhật</div>";
        }

        ltrLichSu.Text = strHTML;
    }

    private void HienThiTuyenDung()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubChuyenMuc> TList_SubChuyenMuc = DataRepository.SubChuyenMucProvider.GetPaged("TenSubChuyenMuc like N'%" + Common.TuyenDung + "%'", "Id", 0, 1, out TotalRows);
        WhereClause += "and TrangThai = 1 and IdSubChuyenMuc = " + TList_SubChuyenMuc[0].Id;

        TList<ChuyenMuc> TList_ChuyenMuc_TuyenDung = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 1, out TotalRows);

        if (TList_ChuyenMuc_TuyenDung.Count > 0)
        {
            strHTML += "<div style=\"width:300px;min-height:315px;height: auto;\">";
            strHTML += "<img class=\"radius\" src=\"Upload/ChuyenMuc/" + TList_ChuyenMuc_TuyenDung[0].AnhDaiDien + "\" width=\"300px\" height=\"150px\" border=\"0\"/>";
            strHTML += "<div style=\"width:300px;min-height:70px;height: auto;margin-bottom:10px;word-wrap:break-word;font-family: Arial, Helvetica, sans-serif;font-size: 13px;color:#696969;padding-top:10px;text-align:justify;\">" + 
                (TList_ChuyenMuc_TuyenDung[0].TomTat.ToString().Length > 150 ? TList_ChuyenMuc_TuyenDung[0].TomTat.Substring(0, 150) + "..." : TList_ChuyenMuc_TuyenDung[0].TomTat.ToString()) + "</div>";
            strHTML += "<div style=\"width:71px; height: 17px; background:url('Images/dltn/seeMoreBg.png') no-repeat;float:right;\">";
            strHTML += "<a href=\"ChuyenMuc/" + TList_ChuyenMuc_TuyenDung[0].Id + "/" + TList_ChuyenMuc_TuyenDung[0].IdSubChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc_TuyenDung[0].TieuDe) + ".aspx\" style=\"text-decoration:none; font-size:12px; padding-left:10px;padding-top:2px;color:#fff;\">Xem tiếp</a></div>";
            strHTML += "</div>";

            string ngay = Common.StandardStringjquery(TList_ChuyenMuc_TuyenDung[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));

            //if ("Ch".Equals(ngay.Substring(0, 2)))
                lblNgayCapNhatTuyenDung.Text = ngay;
            //else
            //    lblNgayCapNhatTuyenDung.Text = "Thứ " + ngay;            
        }
        else
        {
            strHTML = "<div style=\"width:310px;min-height:100px;height: auto;float:left;\">";
            strHTML += "Dữ liệu chưa được cập nhật</div>";
        }

        ltrTuyenDung.Text = strHTML;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    /// <summary>
    /// Phuong thuc thuc hien lay link cua cac sub menu cua Gioi Thieu
    /// </summary>
    /// <param name="gioiThieu"></param>
    /// <returns></returns>
    public string getLinkGioiThieu(string gioiThieu)
    {
        string link = "~/";

        int TotalRows = 0;
        string WhereClause = "1=1";
        TList<SubChuyenMuc> TList_SubChuyenMuc = DataRepository.SubChuyenMucProvider.GetPaged("TenSubChuyenMuc like N'%" + gioiThieu + "%'", "ID", 0, 0, out TotalRows);
        if (TList_SubChuyenMuc.Count > 0)
        {
            WhereClause += " and trangthai =1 and IdSubChuyenMuc in (select Id from SubChuyenMuc where Id = " + TList_SubChuyenMuc[0].Id + " )";
            TList<ChuyenMuc> TList_ChuyenMuc = DataRepository.ChuyenMucProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);
            link += "SubChuyenMuc/" + TList_SubChuyenMuc[0].Id + "/" + TList_SubChuyenMuc[0].IdLoaiChuyenMuc + "/" + GetTieuDe(TList_SubChuyenMuc[0].TenSubChuyenMuc) + ".aspx";
        }
        return link;
    }
}